/* 基础变量 */
:root {
  --primary-color: #6c5ce7;
  --primary-light: #a29bfe;
  --secondary-color: #f8f9fa;
  --user-bubble: #6c5ce7;
  --ai-bubble: #ffffff;
  --text-color: #2d3436;
  --light-text: #636e72;
  --error-color: #d63031;
  --success-color: #00b894;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --border-radius: 16px;
  --small-radius: 12px;
  --message-radius: 20px;
}

/* 基础样式 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* 客服主容器 */
.ai-customer-service {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 450px;
  margin: 0 auto;
  background: #f8f9fa;
  box-shadow: var(--shadow-lg);
  border-radius: var(--border-radius);
  overflow: hidden;
  position: relative;
}

/* 头部样式 */
.chat-header {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
  color: white;
  padding: 20px 16px 16px;
  position: relative;
  z-index: 10;
}

.header-content {
  display: flex;
  align-items: center;
  position: relative;
  z-index: 2;
}

.avatar-container {
  margin-right: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.avatar svg {
  width: 24px;
  height: 24px;
}

.header-text {
  flex: 1;
}

.chat-header h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.status-indicator {
  display: flex;
  align-items: center;
  font-size: 13px;
  opacity: 0.9;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-dot.online {
  background: #55efc4;
  animation: pulse 2s infinite;
}

.status-dot.loading {
  background: #fdcb6e;
}

.header-gradient {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: linear-gradient(135deg, rgba(108, 92, 231, 0.8), rgba(162, 155, 254, 0.8));
  z-index: 1;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

/* 聊天内容区域 */
.chat-container {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: linear-gradient(to bottom, #f8f9fa, #f1f3f5);
  position: relative;
}

.messages-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.welcome-message {
  text-align: center;
  margin-bottom: 24px;
}

.welcome-content {
  display: inline-block;
  background: white;
  padding: 12px 20px;
  border-radius: var(--small-radius);
  box-shadow: var(--shadow-sm);
}

.welcome-content h4 {
  color: var(--primary-color);
  font-size: 14px;
  margin-bottom: 4px;
}

.welcome-content p {
  color: var(--light-text);
  font-size: 12px;
}

/* 消息气泡样式 */
.message {
  display: flex;
}

.message-content {
  display: flex;
  max-width: 85%;
}

.message.user {
  justify-content: flex-end;
}

.message.user .message-content {
  flex-direction: row-reverse;
}

.message.assistant .avatar {
  margin-right: 8px;
}

.text-bubble {
  padding: 12px 16px;
  border-radius: var(--message-radius);
  line-height: 1.5;
  font-size: 15px;
  word-break: break-word;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.message.user .text-bubble {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .text-bubble {
  background: var(--ai-bubble);
  color: var(--text-color);
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 11px;
  color: var(--light-text);
  text-align: right;
  margin-top: 4px;
  opacity: 0.7;
}

.message.user .message-time {
  color: rgba(255, 255, 255, 0.7);
}

/* 输入中指示器 */
.typing-indicator {
  display: flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--light-text);
  border-radius: 50%;
  display: inline-block;
  margin: 0 2px;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* 错误消息 */
.error-message {
  display: flex;
  align-items: center;
  color: white;
  font-size: 13px;
  padding: 10px 16px;
  background: var(--error-color);
  margin: 0 16px;
  border-radius: var(--small-radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.error-icon {
  width: 18px;
  height: 18px;
  background: white;
  color: var(--error-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  margin-right: 8px;
  flex-shrink: 0;
}

.error-text {
  flex: 1;
}

/* 预设问题区域 */
.preset-questions {
  padding: 12px 16px 16px;
  background: white;
}

.preset-header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.divider {
  flex: 1;
  height: 1px;
  background: #eee;
}

.preset-title {
  font-size: 12px;
  color: var(--light-text);
  padding: 0 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.question-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-btn {
  display: flex;
  align-items: center;
  background: var(--secondary-color);
  border: none;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--primary-color);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
}

.preset-btn:hover {
  background: #e6e9f9;
  transform: translateY(-1px);
}

.preset-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.preset-icon {
  margin-right: 6px;
  font-size: 14px;
  display: flex;
  align-items: center;
}

.preset-text {
  white-space: nowrap;
}

/* 输入区域 */
.input-area {
  padding: 12px 16px;
  background: white;
  border-top: 1px solid #eee;
}

.input-wrapper {
  display: flex;
  border: 1px solid #ddd;
  border-radius: 24px;
  overflow: hidden;
  transition: all 0.3s;
  background: white;
  box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2);
}

.input-area input {
  flex: 1;
  border: none;
  padding: 12px 16px;
  outline: none;
  font-size: 15px;
  background: transparent;
}

.input-area input::placeholder {
  color: #b2bec3;
}

.send-btn {
  width: 48px;
  height: 48px;
  background: var(--primary-color);
  border: none;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.send-btn:hover {
  background: #5d4bdb;
}

.send-btn:disabled {
  background: #dfe6fd;
  cursor: not-allowed;
}

.send-icon {
  font-size: 20px;
  transition: transform 0.2s;
}

.send-btn:not(:disabled):hover .send-icon {
  transform: translateX(2px);
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 响应式调整 */
@media (max-width: 480px) {
  .ai-customer-service {
    height: 100vh;
    max-width: 100%;
    border-radius: 0;
  }
  
  .chat-header {
    padding-top: max(20px, env(safe-area-inset-top));
  }
  
  .input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}